<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 2017/3/5
 * Time: 下午5:51
 */
class Download extends MY_M_Controller
{	
    public function index()
    {
    	$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    	
    	
//     	$android = (strpos($agent, 'android')) ? true : false;
//     	if(strpos($agent, 'micromessenger') !== false && $android)
//     	{
//     		header('Location: http://a.app.qq.com/o/simple.jsp?pkgname=com.shike.android');
//     		exit;
//     	}
    	
    	if(strpos($agent, 'micromessenger') !== false )
    	{
    		$this->load->view('m/download');
    	}else{
    	
	    	$iphone = (strpos($agent, 'iphone')) ? true : false;
	    	$ipad = (strpos($agent, 'ipad')) ? true : false;
	    	$android = (strpos($agent, 'android')) ? true : false;

	    	$this->load->model('common/Model_version', 'v');
	    	$ac = config_item('app_client');
	    	if($iphone || $ipad)
	    	{
	    	    $item = $this->v->latest_version(APP_CLIENT_IOS);
	    	    $url = $item['data']['link'];
	    		//$ios_url = $ac[APP_CLIENT_IOS]['link'];
	    		//echo  "<script>alert('等待上线中……')</script>";
	    		echo "<script>window.location.href='$url'</script>";
	    	}else{
                $item = $this->v->latest_version(APP_CLIENT_ANDROID);
                $url = $item['data']['link'];
	    		//$apk_url = $ac[APP_CLIENT_ANDROID]['link'];
	    		header('Location: '.$url);
	    	}
    	}
    }
}